package com.lanhe.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanhe.article.domain.LhArticleContent;
import com.lanhe.article.mapper.LhArticleContentMapper;
import com.lanhe.article.service.ILhArticleContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 文章内容表(LhArticleContent)表服务实现类
 *
 * @author zhanggl
 * @since 2023-12-18 09:23:44
 */
@Service
public class LhArticleContentServiceImpl extends ServiceImpl<LhArticleContentMapper, LhArticleContent> implements ILhArticleContentService {

	@Autowired
	private LhArticleContentMapper articleContentMapper;

	/**
	 * 添加文字内容
	 *
	 * @param articleId 文章id
	 * @param content   文章内容
	 * @return 结果
	 * @author zhanggl
	 * @date 2023/12/18
	 */
	@Override
	public int insertArticleContent(Long articleId, String content) {
		LhArticleContent articleContent = new LhArticleContent();
		articleContent.setArticleId(articleId);
		articleContent.setContent(content);
		return articleContentMapper.insert(articleContent);
	}

	/**
	 * 修改文章内容
	 *
	 * @param articleId 文章id
	 * @param content   文章内容
	 * @return int
	 * @author zhanggl
	 * @date 2023/12/18
	 */
	@Override
	public int updateArticleContent(Long articleId, String content) {
		LambdaUpdateWrapper<LhArticleContent> wrapper = new LambdaUpdateWrapper<>();
		wrapper.eq(LhArticleContent::getArticleId, articleId);
		LhArticleContent articleContent = new LhArticleContent();
		articleContent.setContent(content);
		return articleContentMapper.update(articleContent, wrapper);
	}

	/**
	 * 根据文章ID获取内容
	 *
	 * @param articleId 文章ID
	 * @return com.lanhe.article.domain.LhArticleContent
	 * @author zhanggl
	 * @date 2023/12/18
	 */
	@Override
	public LhArticleContent selectArticleContentByArticleId(Long articleId) {

		LambdaQueryWrapper<LhArticleContent> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(LhArticleContent::getArticleId, articleId);
		return articleContentMapper.selectOne(wrapper);
	}
}

